package com.swjd.jingle.adapter;

import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import androidx.fragment.app.FragmentActivity;

import com.swjd.jingle.R;
import com.swjd.jingle.pojo.User;

import butterknife.BindView;
import butterknife.ButterKnife;

public class UserInfoAdapter extends BaseAdapter {
    private FragmentActivity context;
    private String[] names;

    public UserInfoAdapter(FragmentActivity context, String[] names, User user) {
        this.context = context;
        this.names = names;
    }

    @Override
    public int getCount() {
        return names.length;
    }

    @Override
    public Object getItem(int position) {
        return names[position];
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder =null;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.item_user_info, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }
        holder.tvItem.setText(names[position]);
        return convertView;
    }

    class ViewHolder {
        @BindView(R.id.tv_item)
        TextView tvItem;
        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
